;;; packages.el --- Spacemacs Project Management Layer packages File  -*- lexical-binding: nil; -*-
;;
;; Copyright (c) 2012-2025 Sylvain Benner & Contributors
;;
;; Author: Sylvain Benner <sylvain.benner@gmail.com>
;; URL: https://github.com/syl20bnr/spacemacs
;;
;; This file is not part of GNU Emacs.
;;
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with this program.  If not, see <http://www.gnu.org/licenses/>.

(defconst spacemacs-project-packages
  '(projectile))

(defun spacemacs-project/init-projectile ()
  (use-package projectile
    :commands (projectile-ack
               projectile-ag
               projectile-compile-project
               projectile-dired
               projectile-find-dir
               projectile-find-file
               projectile-find-tag
               projectile-test-project
               projectile-grep
               projectile-invalidate-cache
               projectile-kill-buffers
               projectile-multi-occur
               projectile-project-p
               projectile-project-root
               projectile-recentf
               projectile-regenerate-tags
               projectile-replace
               projectile-replace-regexp
               projectile-run-async-shell-command-in-root
               projectile-run-shell-command-in-root
               projectile-switch-project
               projectile-switch-to-buffer
               projectile-vc)
    :init
    ;; note for Windows: GNU find or Cygwin find must be in path to enable
    ;; fast indexing. Also, because windows ships with a program called
    ;; c:\windows\system32\find.exe that is very much not findutils find
    ;; we ignore that specific executable
    (when (and (spacemacs/system-is-mswindows) (executable-find "find")
               (not (file-in-directory-p
                     (executable-find "find") "C:\\Windows")))
      (setq  projectile-indexing-method 'alien
             projectile-generic-command "find . -type f"))
    (setq projectile-sort-order 'recentf
          projectile-cache-file (concat spacemacs-cache-directory
                                        "projectile.cache")
          projectile-known-projects-file (concat spacemacs-cache-directory
                                                 "projectile-bookmarks.eld"))
    (spacemacs/set-leader-keys
      ;; File path
      "fyC" 'spacemacs/projectile-copy-file-path-with-line-column
      "fyD" 'spacemacs/projectile-copy-directory-path
      "fyL" 'spacemacs/projectile-copy-file-path-with-line
      "fyY" 'spacemacs/projectile-copy-file-path
      ;; Project
      "p!" 'projectile-run-shell-command-in-root
      "p&" 'projectile-run-async-shell-command-in-root
      "p%" 'projectile-replace-regexp
      "pa" 'projectile-toggle-between-implementation-and-test
      "pb" 'projectile-switch-to-buffer
      "pc" 'projectile-compile-project
      "pu" 'projectile-run-project
      "pd" 'projectile-find-dir
      "pD" 'projectile-dired
      "pe" 'projectile-edit-dir-locals
      "pf" 'projectile-find-file
      "pF" 'projectile-find-file-dwim
      "pE" 'projectile-find-references
      "pg" 'projectile-find-tag
      "pG" 'projectile-regenerate-tags
      "pi" 'projectile-install-project
      "pI" 'projectile-invalidate-cache
      "pk" 'projectile-kill-buffers
      "pp" 'projectile-switch-project
      "pr" 'projectile-recentf
      "pR" 'projectile-replace
      "pT" 'projectile-test-project
      "pv" 'projectile-vc)
    :config
    (projectile-mode)
    (spacemacs|hide-lighter projectile-mode)))
